package com.kma.summer2012.client.view.manager;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.*;
import com.kma.summer2012.client.constants.ConstantsPresenter;
import com.kma.summer2012.client.presenters.manager.AddWorkCategoryPresenter;
import com.kma.summer2012.client.styles.style2.Recources;

import java.util.Map;

public class AddWorkCategoryView extends Composite implements AddWorkCategoryPresenter.Display {
    interface AddWorkCategoryViewUiBinder extends UiBinder<Widget, AddWorkCategoryView> {
    }

    private static AddWorkCategoryViewUiBinder ourUiBinder = GWT.create(AddWorkCategoryViewUiBinder.class);
    public static ConstantsPresenter constants;
    @UiField
    protected Label pageTitle;
    @UiField
    protected TextBox categoryName;

    @UiField
    protected TextArea categoryDescription;

    @UiField
    protected ListBox categoryList;

    @UiField
    protected Button saveButton;
    @UiField
    protected Button cancelButton;

    @Override
    public void setName(String name) {
        this.categoryName.setValue(name);
    }

    @Override
    public String getName() {
        return this.categoryName.getValue();
    }

    @Override
    public void setDescription(String description) {
        this.categoryDescription.setValue(description);
    }

    @Override
    public String getDescription() {
        return this.categoryDescription.getValue();
    }

    @Override
    public HasClickHandlers getSaveButton() {
        return saveButton;
    }

    @Override
    public HasClickHandlers getCancelButton() {
        return cancelButton;
    }

    @Override
    public void setSelectedParent(int category) {
        this.categoryList.setSelectedIndex(category);
    }

    @Override
    public int getSelectedParent() {
        return this.categoryList.getSelectedIndex();
    }

    @Override
    public void setCategoryList(Map<Integer, String> list) {
        this.categoryList.clear();
        this.categoryList.insertItem("<ROOT>", 0);
        for (Integer i : list.keySet()) {
            this.categoryList.insertItem(list.get(i), i);
        }
    }

    public AddWorkCategoryView() {
        HTMLPanel rootElement = (HTMLPanel) ourUiBinder.createAndBindUi(this);
        constants = GWT.create(ConstantsPresenter.class);

        pageTitle.setText(constants.CATEGORY_ADD());
        pageTitle.setStyleName(Recources.INSTANCE.styles().titleCatalog());
        categoryName.setStyleName(Recources.INSTANCE.styles().input());
        categoryDescription.setStyleName(Recources.INSTANCE.styles().textarea());


        saveButton.addStyleName(Recources.INSTANCE.styles().Caption());
        cancelButton.addStyleName(Recources.INSTANCE.styles().Caption());

        initWidget(rootElement);

    }
}